\documentclass{article}
\usepackage{polski}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage[usenames,dvipsnames]{color} % For colors and names
\hyphenpenalty=1115000
\title{\textbf{Intelligent Information Systems 12L} \\ Forward reasoning agent playing Wympus World\\ Report} % Title

\author{Tomasz \textsc{Bawej} \\ Łukasz \textsc{Trzaska}} % Author name

\definecolor{mygrey}{gray}{.96} % Light Grey
\lstset{language=Verilog, tabsize=3, backgroundcolor=\color{mygrey}, basicstyle=\small, commentstyle=\color{BrickRed}}
\lstset{ 
	language=[ISO]C++,              % choose the language of the code ("language=Verilog" is popular as well)
   	tabsize=3,							  % sets the size of the tabs in spaces (1 Tab is replaced with 3 spaces)
	basicstyle=\scriptsize,               % the size of the fonts that are used for the code
	numbers=left,                   % where to put the line-numbers
	numberstyle=\scriptsize,              % the size of the fonts that are used for the line-numbers
	stepnumber=2,                   % the step between two line-numbers. If it's 1 each line will be numbered
	numbersep=5pt,                  % how far the line-numbers are from the code
	backgroundcolor=\color{mygrey}, % choose the background color. You must add \usepackage{color}
	%showspaces=false,              % show spaces adding particular underscores
	%showstringspaces=false,        % underline spaces within strings
	%showtabs=false,                % show tabs within strings adding particular underscores
	frame=single,	                 % adds a frame around the code
	captionpos=b,                   % sets the caption-position to bottom
	breaklines=true,                % sets automatic line breaking
	breakatwhitespace=false,        % sets if automatic breaks should only happen at whitespace
	%escapeinside={\%*}{*)},        % if you want to add a comment within your code
	commentstyle=\color{BrickRed}   % sets the comment style
}
\newenvironment{packed_enum}{
\begin{enumerate}
  \setlength{\itemsep}{1pt}
  \setlength{\parskip}{0pt}
  \setlength{\parsep}{0pt}
}{\end{enumerate}}
\begin{document}
\setlength\parindent{0pt} % Removes all indentation from paragraphs
\maketitle
\section{Subject}
\textbf{Wumpus world and forward reasoning: } 
describe in formal language knowledge necessary for knowledge-based agent playing in the game Wumpus World. Algorithm of choosing an action, should use forward-reasoning engine. Rules of Wumpus World are described in the book \textit{Russell, Stuart J. (2010), Artificial Intelligence A Modern Approach. New Jersey: Pearson Education, Inc. ISBN 0-13-604259-7}.
\section{Implementation}
To implement given task Java programming language was used.
\paragraph*{Significant details.} 
As a framework, providing simulation environment, \textit{Wumpus-Lite} was used (source url: \textit{http://www.cs.uic.edu/~jbiagion/wumpuslite.html}). A forward-reasoning engine was implemented without external libraries. \\
Although, reasoning engine is implemented implicitly, one can single out important ideas. The basic data structure for holding knowledge is: 
\begin{center} {\scriptsize $ private HashMap\langle Starting, Boolean\rangle knowledge\; $ }\\ \end{center}
Facts are saved to and retrieved from the knowledge base by calling \textit{tell} and \textit{ask} methods accordingly, as it used to be done in similar solutions.
\section{Knowledge definition}
This paragraph describes knowledge necessary for knowledge-based agent to play Wumpus World game.\\
Assumptions:
\begin{packed_enum}
\item There is one and only one Wumpus od the board and he is not moving.
\item There is one or more pits.
\end{packed_enum}
{\scriptsize 
\textbf{Constants:}\\
$ BOARD\_SIZE = N $\\
\\
\textbf{Aims:}\\
$ Has\_gold(Agent, true) \wedge Left\_board(Agent, true) $\\
\\
\textbf{Start conditions:}\\
$ Killed\_Wumpus(false), Safe(L(1,1)), Has\_gold(Agent, false), Left\_board(Agent, false)$
\\
}
\\
\textbf{Rules in formal logic:}
{\scriptsize
\begin{packed_enum}
\item $ Exclusive\_neighbour(a(x,y), b(w,z)) \Longleftarrow $
$ Equal(x,w) \wedge [Equal(y, z+1) \wedge Equal(y, z-1)] \vee$  
$ Equal(y,z) \wedge [Equal(x, w+1) \wedge Equal(x, w-1)] $
\item $ Neighbour(a, b) \Longleftarrow Exclusive\_neighbour(a,b) \vee Neighbour(b, a) $
\item $ Obstacle(A(x,y)) \Longleftarrow $
$ [ Lower(x,1) \vee Greater(x, BOARD\_SIZE) \vee Lower(y,1) \vee Greater(y, BOARD\_SIZE) ] $
\item $ Obstacle(a) \Longleftarrow [ Bumped(a) ] $
\item $ On\_gold(Agent) \Longleftarrow [ On(Agent, l) \wedge Glittering(l) ] $
\item $ Safe(l) \Longleftarrow Visited(Agent, l) $
\item $ Safe(Exclusive\_neighbour(l)) \Longleftarrow [ \neg Breezy(l) \wedge \neg Stenchy(l) ] $
\item $ Killed\_Wumpus(true) \Longleftarrow [ Scream(l) ] $
\\
\item $ Possible\_Wumpus(l(x+1,y), l1) \Longleftarrow $ \\ $[ Stenchy(l1(x,y)) \wedge \neg Safe(l(x+1,y)) \wedge \neg Wumpus(l(x+1,y))] $
\item $ Possible\_Wumpus(l(x-1,y), l1) \Longleftarrow $ \\ $[ Stenchy(l1(x,y)) \wedge \neg Safe(l(x-1,y)) \wedge \neg Wumpus(l(x-1,y)) ] $
\item $ Possible\_Wumpus(l(x,y+1), l1) \Longleftarrow $ \\ $[ Stenchy(l1(x,y)) \wedge \neg Safe(l(x,y+1)) \wedge \neg Wumpus(l(x,y+1))] $
\item $ Possible\_Wumpus(l(x,y-1), l1) \Longleftarrow $ \\ $[ Stenchy(l1(x,y)) \wedge \neg Safe(l(x,y-1)) \wedge \neg Wumpus(l(x,y-1)) ] $
\item $ Wumpus(l) \Longleftarrow [ Possible\_Wumpus(l, x) \wedge Possible\_Wumpus(l, y) \wedge \neg Equal(x, y) ] $
\\
\item $ Possible\_Pit(l(x+1,y)) \Longleftarrow $ \\ $ [ Breezy(l1(x,y)) \wedge \neg Safe(l(x+1,y)) \wedge \neg Pit(l(x+1,y)) ] $
\item $ Possible\_Pit(l(x-1,y)) \Longleftarrow $ \\ $ [ Breezy(l1(x,y)) \wedge \neg Safe(l(x-1,y)) \wedge \neg Pit(l(x-1,y)) ] $
\item $ Possible\_Pit(l(x,y+1)) \Longleftarrow $ \\ $ [ Breezy(l1(x,y)) \wedge \neg Safe(l(x,y+1)) \wedge \neg Pit(l(x,y+1)) ] $
\item $ Possible\_Pit(l(x,y-1)) \Longleftarrow $ \\ $[ Breezy(l1(x,y)) \wedge \neg Safe(l(x,y-1)) \wedge \neg Pit(l(x,y-1)) ] $
\item $ Pit(l) \Longleftarrow $ \\ $ [ Possible\_Pit(l, x) \wedge Possible\_Pit(l, y) \wedge Possible\_Pit(l, z) \wedge Possible\_Pit(l, w) \wedge \neg Equal(x, y, z, w) ] $
\end{packed_enum}
}
\textbf{Algorithm of making decision by agent}\\
Fact collected and saved by Agent for each movement accordingly: \\
{\scriptsize
$ Stenchy(L(x, y)), Breezy(L(x,y)), Bumped(L(x,y)), Glitter(L(x,y)), Scream(L(x,y)), $ \\ $ Visited(Previous\_Location) $,
where $ x, y are coordinates of Agent on board. $ 
}\\
After saving vector of \textit{percepts} Agent infers where are particular object on board. He is cautious, moves only on fields, which are definitely safe (fact: $ Safe(l(x,y)) $).
If he meets Wumpus on his way and he didn't use arrow yet, he try to hunt Wumpus. His main goal is to explore the board. If he receives glitter percept, he collects gold and heads to exit.
\pagebreak
\section{Running instruction}
To the present document, there should be delivered source code and runnable application in file: \textit{ EINIS\_wumpus.jar}. To run application Java Virtual Machine 1.7 should be installed and below command should be run in the command line: 
\begin{center}
{\scriptsize java -jar EINIS\_wumpus.jar}
\end{center}
\section{Simulation results}
\textbf{Input parameters:}\\
Number of tests: 50 000\\
Board size: 6 x 6\\
\textbf{Results:}\\
Points avg.: 552.27\\
Points min.: -1008.0\\
Points max.: 999.0
\end{document}